package cn.yunhe.service.serviceImpl;


import cn.yunhe.dao.UserExamHistoryDao;
import cn.yunhe.entity.UserExamHistory;
import cn.yunhe.service.UserExamHistoryService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("userExamHistoryService")
public class UserExamHistoryServiceImpl implements UserExamHistoryService {
    @Autowired
    @Qualifier("userExamHistoryDao")
    private UserExamHistoryDao userExamHistoryDao;

    @Override
    public List<UserExamHistory> UserExamHistory(String username) {
        return userExamHistoryDao.UserExamHistory(username);
    }


    public Page getUserExamInfo(Map cond) {
        //创建一个新的怕个对象
        Page page = new Page();
        //计算总记录数
        page.setTotal(userExamHistoryDao.getUserExamInfoCount(cond));
        //获取页大小
        int pageSize = (int) cond.get("pageSize");
        page.setPageSize(pageSize);
        //获取当前页
        int currPageNum = (int) cond.get("pageNum");
        page.setPageNum(currPageNum);
        //计算总页数
        page.setPageNum((int)(page.getTotal()/pageSize+(page.getTotal()%pageSize==0? 0:1)));
        //启用分页
        page = PageHelper.startPage(currPageNum,pageSize);
        List userExamInfoList = userExamHistoryDao.getUserExamInfo(cond);
        return page;
    }

    public UserExamHistoryDao getUserExamHistoryDao() {
        return userExamHistoryDao;
    }

    public void setUserExamHistoryDao(UserExamHistoryDao userExamHistoryDao) {
        this.userExamHistoryDao = userExamHistoryDao;
    }
}
